import Login from '../pages/login/Login';
import MyLayout from '../shared/MyLayout';
import Home from '../pages/home/Home';
import Chat from '@/pages/chat/Chat';
import My from '@/pages/my/My';
import Good from '@/pages/good/Good';
import GoodDetail from '@/pages/good/GoodDetail';
import { IndexRouteObject, NonIndexRouteObject } from 'react-router-dom';
import ErrorBoundary from './errorBoundary';

interface CustomIndexRouteObject extends IndexRouteObject {
  title?: string;
}

interface CustomNonIndexRouteObject extends NonIndexRouteObject {
  title?: string;
  children?: CustomRouteObject[];
}

type CustomRouteObject = CustomIndexRouteObject | CustomNonIndexRouteObject;

const routes: CustomRouteObject[] = [
  {
    path: '/',
    Component: MyLayout,
    errorElement: <ErrorBoundary />,
    title: '',
    children: [
      {
        index: true,
        Component: Home,
        title: '首页',
      },
      {
        path: 'chat',
        Component: Chat,
        title: '图表',
      },
      {
        path: 'good',
        children: [
          { index: true, Component: Good, title: '商品' },
          {
            path: 'detail/:id',
            Component: GoodDetail,
            title: '商品详情',
          },
        ],
      },
      {
        path: 'my',
        title: '我的',
        Component: My,
      },
    ],
  },
  { path: '/login', Component: Login },
];

export default routes;
